<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
	<body>
		<script type="text/javascript">

			function Node(){
				this.left=null;
				this.right=null;
				this.value=null;
			}

			Node.prototype.add = function(value){
				if(value!=null && typeof(value)!='undefined'){
					if(this.value==null){
						this.value = value;
						return;
					}

					var node = new Node();
					node.value=value;
					if(this.value>=value){
						if(this.left==null){
							this.left = node;
						}else{
							this.left.add(value);
						}
					}else{
						if(this.right==null){
							this.right = node;
						}else{
							this.right.add(value);
						}
					}
				}
			}

			Node.prototype.print=function(data){
				if(this.left!=null){
					this.left.print(data);
				}
				data.push(this.value);
				if(this.right!=null){
					this.right.print(data);
				}
			}

			function app(){
				var data=[2,6,56,102,5,4,47,7000,200,45,24,85,63,954,6222,5];
				var root = new Node();
				for(var i=0;i<data.length;i++){
					root.add(data[i]);
				}
				var rs = [];
				root.print(rs);
				console.log(rs.join(","));
			}

			app();

		</script>
	</body>
</html>
